package kr.hkit.androidcomplete01.chapter09;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class ContextMenuEx extends Activity {
	Button mBtn;
	EditText mEdit;
	MyImage mImg;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch09_contextmenuex);
		
		mBtn = (Button)findViewById(R.id.ch09_contextmenubtn01);
		mEdit = (EditText)findViewById(R.id.ch09_contextmenutext02);
		mImg = (MyImage)findViewById(R.id.ch09_contextnemu_myimage);
		
		registerForContextMenu(mBtn);
		registerForContextMenu(mEdit);
		registerForContextMenu(mImg);
		
	}
	
	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		super.onCreateContextMenu(menu, v, menuInfo);
		if(v == mBtn){
			menu.setHeaderTitle("버튼 메뉴");
			menu.add(0,1,0,"Red");
			menu.add(0,2,0,"Blue");
			menu.add(0,3,0,"Green");
		}
		if(v == mEdit){
			menu.setHeaderTitle("에디트 텍스트 메뉴");
			menu.add(0,4,0,"번역하기");
			menu.add(0,5,0,"필기인식");
		}
	}
	
	@Override
	public boolean onContextItemSelected(MenuItem item) {
		switch(item.getItemId()){
		case 1: mBtn.setTextColor(Color.RED); return true;
		case 2: mBtn.setTextColor(Color.BLUE); return true;
		case 3: mBtn.setTextColor(Color.GREEN); return true;
		case 4: mEdit.setText("번역했다"); return true;
		case 5: mEdit.setText("필기인식했다"); return true;
		case 100: Toast.makeText(this, "이미지회전", Toast.LENGTH_LONG).show(); return true;  
		case 101: Toast.makeText(this, "크기변경", Toast.LENGTH_LONG).show(); return true;
		}
		return false;
	}
	
	
}
